Total Complexity | 6 |
Total Lines | 24 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { toArray } from 'myrmidon'; |
||
4 | export default class Cottus { |
||
5 | constructor(conf = {}) { |
||
6 | this.rules = {}; |
||
7 | this.addRules(conf.rules || []); |
||
8 | } |
||
9 | |||
10 | compile(schema, parentContext) { |
||
11 | const validator = new Validator(this, schema, parentContext); |
||
12 | |||
13 | validator.parse(); |
||
14 | |||
15 | return validator; |
||
16 | } |
||
17 | |||
18 | addRules(rules) { |
||
19 | rules.forEach(rule => { |
||
20 | toArray(rule.schema).forEach(schemaKey => this.rules[schemaKey] = rule); |
||
21 | }); |
||
22 | } |
||
23 | |||
24 | addRule(rule) { |
||
25 | this.addRules([ rule ]); |
||
26 | } |
||
27 | } |
||
28 |